<% require 'gchart' %>
<% content_for :title, "Reporting" %>
<script language="JavaScript">
function hidediv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
</script>

<script>

function hideShow(myElement, textAfficher, textAfficher2){
	//var myDiv = document.getElementById(myElement);
	var stateDiv = document.getElementById('stateDiv');
	if(stateDiv.innerHTML == textAfficher){
		stateDiv.innerHTML = textAfficher2;
		showdiv(myElement);
	}else{
		stateDiv.innerHTML = textAfficher;
		hidediv(myElement);
	}
}
</script>
<% if !@error  %>

<div id='stats_page'>
	<div id='search_form'>
	
	<%= error_messages_for :stats %>
	<h1>Informations périodiques</h1>
	<h2>Formulaire de recherche détaillée<h2>
	<% form_tag :controller => 'stats/index' do %>
		<table>
			<tr>
				<th>Date de début</th>
				<th>Date de fin</th>
				<th>Type de recherche(par période)</th>
			</tr>
			<tr>
				<td>
					<%= date_select('dated', 'start_date', :order => [:month, :day, :year])%>
				</td>
				<td>
					<%= date_select('datef', 'end_date', :order => [:month, :day, :year])%>
				</td>
				<td colspan='2'>
					<%= select_tag(:period_id, options_for_select([['jour', 1], ['Semaine', 2], ['Mois', 3]])) %><br />
				</td>
			</tr>
			<tr>
				<td colspan='3'>	
				<%= submit_tag 'Envoyer' %>
				</td>
			</tr>
			
		</table>
	<% end %>
	</div>
	<div id='stateDiv' onclick ='hideShow("global_informations", "+ Afficher stats globales", "- Afficher stats globales");' >+ Afficher stats globales</div>
	<div id='global_informations' style='display:none;'>
		<table>
			<tr>
				<td>
					<h2 class='stats'>Information génarales</h1>
				</td>
			</tr>
			<tr>
				<td>Nombre de salles : <%= @nb_rooms %></td>
			</tr>
			<tr>
				<td>Nombre d'ordinateurs : <%= @nb_computers %></td>
			</tr>
			<tr>
				<td>Nombre moyen d'ordinateurs par salle : <%= @avg_comp_room %></td>
			</tr>
			<tr>
				<td>
					Temps moyen pour résoudre un probléme : 
					<% @avg_resolved_events_all.each do |@a| %>
						<%= (@a.periodbetween.to_i/(60*60*24)) %>
					<% end %> 
					jours
				</td>
			</tr>
		</table>
	</div>

	<div>
		
		<table>
			<tr>
				<th colspan ='3' class='header_stats_periodique'>
					Date du <span ><%= @date_debut %></span> au <span><%= @date_fin %></span>
				</th>
			</tr>
			<tr>
				<th>incidents non résolus </th>
				<th>incidents résolus</th>
				<th>Temps moyen pour résoudre un incident</th>
				
			</tr>
			<tr>
				<td><%= @events_last_week_nresolved %></td>
				<td><%= @events_last_week_resolved %></td>
				<td>					
					<% @avg_resolved_events_all.each do |@a| %>
						<%= (@a.periodbetween.to_i/(60*60*24)) %>
					<% end %>
					jours
				</td>
				
			</tr>
		</table>
	</div>
	<% if @events_last_week_nresolved == 0 && @events_last_week_resolved == 0 %>
		<div class='error'>Il n y a pas assez d'informations pour afficher les graphiques</div>
	<% else %>
		<div id='graphics_stats'>
			<p class='graph1'>
				<img class='image_graph' src="<%=Gchart.pie_3d(:data => [@events_last_week_nresolved, @events_last_week_resolved],
						:size => '750x400', 
						:title => "Camembert de tous les incidents du #{@date_debut} au #{@date_fin}",
						:legend => ['Non résolus', 'Résolus'],
						:bar_colors => ['B9121B,4BB5C1'],
						:bg_color => ["FFFFFF"],
						:labels => ['Non résolus', 'Résolus'],
						:title_color => '000000', 
						:title_size => '20',
						:legend_position => 'top', 
						:title_alignment =>'left',
						:left_margin => '150px'
				)%>"/>
			</p>
			<p class='graph2'>
				<img class='image_graph' src="<%=Gchart.bar(
						:data => [@events_by_week_nsolved, @events_by_week_solved],
						:size => '750x400',
						:title => "graphique incidents du #{@date_debut} au #{@date_fin}",
						:legend => ['Résolus','Non résolus'],
						:legend_position => 'top',
						:title_color => '000000', 
						:title_size => '20', 
						:title_alignment =>'left',
						:color => ['852654','258456'],
						:bar_colors => ['4BB5C1,B9121B'],
		           		:stacked => false,
		           		:bg_color => ["FFFFFF"],
		           		:axis_with_labels => 'x,y',
		           		#:axis_labels => [@labels_x_date, ],
		           		:max_value => @max+1
		           		#:rotate=> "vertical",
		           		#:custom => 'chg=10,15,1,0'
				)%>"/>
			</p>
		</div>
	<% end %>
</div>
<% end %>
